package com.web.server.common.utils;

import com.web.server.common.response.Page;
import com.web.server.common.response.Response;
import com.web.server.common.response.Page;
import com.web.server.common.response.Response;

import java.util.List;

/**
 * Created by Rizon on 16/4/26.
 */
public abstract class PageUtil {
        Response response = new Response();
        String pageSize;
        String pageNo;
        protected int count;
        protected int pSize = 10;
        protected int rStart = 0;
        public PageUtil( String pageSize, String pageNo){
            this.pageSize = pageSize;
            this.pageNo = pageNo;
        }
        protected abstract List DoIt();
        public Response execute(){
            int pNo = 1;

            if (pageSize != null) {
                try {
                    pSize = Integer.parseInt(pageSize);
                } catch (Exception e) {
                    pSize = 10;
                }
            }
            if (pageNo != null) {
                try {
                    pNo = Integer.parseInt(pageNo);
                    rStart = (pNo - 1) * pSize;
                } catch (Exception e) {
                    rStart = 0;
                }
            }
            List t = DoIt();
            response.setData(new Page(t, count, pSize, pNo));
            return response;
        }
    }

